<?php

class ComptesJson {
	public function display(ContextExecution $p_contexte){
        $userid = $p_contexte->getUser()->userId;
        $numeroCompte = $p_contexte->m_dataRequest->getData('numeroCompte');
        if($numeroCompte==null){
            
            $listSolde = new ListDynamicObject();
            $listSolde->name='SommeOperation';
            $listSolde->setAssociatedRequest(null, 'SELECT SUM(montant) AS somme, noCompte FROM operation where noCompte=\'$parent->numeroCompte\'');
            
            $list = new ListObject();
            $list->name='ListeComptes';
            $list->setAssociatedKey($listSolde);
            $list->request('Comptes', "userId=$userid");
            $p_contexte->addDataBlockRow($list);
        } else {
            $compte = new Comptes();
            $compte->numeroCompte = $numeroCompte;
            $compte->userId = $userid;
            $compte->load();
            $p_contexte->addDataBlockRow($compte);
        }
    }
}

?>